@extends('backstage.layout.master')
@section('title', '标签下的绑定的素材')
@section('style')
<link rel="stylesheet" href="backstage/assets/css/bootstrap-timepicker.css"/>
<link rel="stylesheet" href="backstage/assets/css/daterangepicker.css"/>
<link rel="stylesheet" href="backstage/assets/css/colorpicker.css"/>
<link rel="stylesheet" href="backstage/assets/css/datepicker.css"/>
@stop
@section('content')
    <style>
        .state li {
            list-style: none;
            float: left;
            padding: 0 20px;
            text-align: center;
            height: 40px;
            line-height: 40px;
        }

        .state ul {
            margin: 0;
        }

        .state a {
            font-size: 12px;
        }
        .che a {
            font-weight: bold;
            color: #151a7c;
        }
    </style>
    <div class="breadcrumbs" id="breadcrumbs">
        <script type="text/javascript">
            try {
                ace.settings.check('breadcrumbs', 'fixed')
            } catch (e) {
            }
        </script>

        <ul class="breadcrumb">
            <li>
                <i class="icon-home home-icon"></i>
                <a target="_blank" href="backstage/home">主页</a>
            </li>

            <li class="active">
                <a target="_blank" href="/backstage/source-pic/source-pic-tag-list">素材标签列表</a>
            </li>
            <li>
                标签绑定素材列表
            </li>
        </ul><!-- .breadcrumb -->

        <div class="nav-search" id="nav-search">
        </div><!-- #nav-search -->
    </div>

    <div class="page-content">
        <div class="page-header">
            <h1>
                素材标签列表
                <small>
                    <i class="icon-double-angle-right"></i>
                    标签绑定素材列表
                </small>
            </h1>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <h3 class="header smaller lighter red">标签简介：</h3>
                <div class="well">
                    <h4 class="green smaller lighter">标签参数</h4>
                    1、标签编号：{{isset($tag->id)?$tag->id:""}}</br>
                    2、标签名：{{isset($tag->tag_name)?$tag->tag_name:""}}</br>
                    3、有无绑定子标签：
                    @if(isset($tag->has_sub_tag)&&($tag->has_sub_tag==1))
                     有
                    @elseif(isset($tag->has_sub_tag)&&($tag->has_sub_tag===0))
                      无
                    @else
                    @endif
                     </br>
                    4、当前标签是否获取全部素材：
                        @if(isset($tag->tag_type)&&($tag->tag_type==1))
                            是
                        @else
                            不是
                        @endif
                        </br>
                </div>
            </div>
            <div class="col-xs-12">
                <!-- PAGE CONTENT BEGINS -->
                @if(isset($tag->tag_type)&&($tag->tag_type==2))
                <div class="alert alert-info">
                    <i class="icon-hand-right"></i>
                    素材添加:&nbsp
                    <select>
                        <option selected>素材编号</option>
                    </select>
                    <input type="text" id="add_source_pic_id">
                    <button onclick="addRang('{{isset($tag->id)?$tag->id:0}}')">添加</button>
                </div>
                @endif
                <table id="sample-table-1" class="table table-striped table-bordered table-hover">
                    <thead>
                    <tr>
                        <th class="center">
                            <label>
                                <input type="checkbox" class="ace">
                                <span class="lbl"></span>
                            </label>
                        </th>
                        <th>素材编号</th>
                        <th class="hidden-480" width="120px">缩略图</th>
                        <th>审核状态</th>
                        <th>用户</th>
                        <th>排序</th>
                        <th>上架状态</th>
                        <th>显示状态</th>
                        <th>更新时间</th>
                        <th>操作</th>
                    </tr>
                    </thead>

                    <tbody>
                    @foreach ($tag_resource_maps as $tag_resource_map)
                        <tr class="" data-tr-id="{{isset($tag_resource_map->tag_resource_map_id)?$tag_resource_map->tag_resource_map_id:0}}">
                            <td class="center">
                                <label>
                                    <input type="checkbox" class="ace">
                                    <span class="lbl"></span>
                                </label>
                            </td>
                            <td>
                                {{isset($tag_resource_map->source_pic_id)?$tag_resource_map->source_pic_id:''}}
                            </td>
                            <td class="hidden-480"><img src="{{isset($tag_resource_map->small_image)?$tag_resource_map->small_image:''}}" width="100" ></td>
                            <td>
                                {{isset($tag_resource_map->audit_value)?$tag_resource_map->audit_value:''}}
                            </td>
                            <td>
                                {{isset($tag_resource_map->user_name)?$tag_resource_map->user_name:''}}
                            </td>
                            <td style="width:68px;">
                                <input type="number" min=1 step=1 name="sort" value="{{$tag_resource_map->sort?$tag_resource_map->sort:10}}" class="sort" style="width:50px;">
                                <input type="hidden" value="{{$tag_resource_map->sort?$tag_resource_map->sort:10}}">
                                <input type="hidden" value="{{isset($tag_resource_map->tag_resource_map_id)?$tag_resource_map->tag_resource_map_id:0}}">
                            </td>
                            <td>
                                @if(isset($tag_resource_map->is_shelves)&&($tag_resource_map->is_shelves==0))
                                    已下架
                                @elseif(isset($tag_resource_map->is_shelves)&&($tag_resource_map->is_shelves==1))
                                    已上架
                                @else
                                @endif
                            </td>
                            <td>
                                @if(isset($tag_resource_map->is_show)&&($tag_resource_map->is_show==0))
                                    隐藏
                                @elseif(isset($tag_resource_map->is_show)&&($tag_resource_map->is_show==1))
                                    显示
                                @else
                                @endif
                            </td>
                            <td>
                                {{isset($tag_resource_map->updated_at)?date('Y-m-d H:i:s',$tag_resource_map->updated_at):''}}
                            </td>
                            <td class="center" style="width:68px;">
                                <div class="visible-md visible-lg hidden-sm hidden-xs action-buttons">
                                    <a class="deletechannel" title="删除" style="color:#d77600;cursor: pointer;" onclick="deleteTagResourceMap({{$tag_resource_map->tag_resource_map_id}})">
                                        <i class="icon-trash bigger-130"></i>
                                    </a>
                                </div>
                            </td>
                        </tr>
                    @endforeach
                    </tbody>
                </table>
                <div class="row">
                    <div class="col-sm-6">
                        <div class="dataTables_info" id="sample-table-2_info"></div>
                    </div>
                    <div class="col-sm-6">
                        <div class="dataTables_paginate paging_bootstrap">
                            <?php echo $tag_resource_maps->render(); ?>
                        </div>
                    </div>
                </div>
                <!-- PAGE CONTENT ENDS -->
            </div><!-- /.col -->
        </div><!-- /.row -->
    </div><!-- /.page-content -->
@stop
@section('script')
    <script src="backstage/assets/js/date-time/bootstrap-datepicker.min.js"></script>
    <script src="backstage/assets/js/date-time/bootstrap-timepicker.min.js"></script>
    <script src="backstage/assets/js/date-time/moment.min.js"></script>
    <script src="backstage/assets/js/date-time/daterangepicker.min.js"></script>
    <script type="text/javascript">
        $(function () {
            $('input[name=date-range-picker]').daterangepicker().prev().on(ace.click_event, function () {
                $(this).next().focus();
            });
            $(".sort").blur(function(){
                var sort = $(this).next().val();
                var newSort = $(this).val();
                var id = $(this).next().next().val();
                var a = $(this);
                console.log('newSort:'+newSort);
                $.ajax({
                    type: "POST",
                    url: "/backstage/source-pic/update-tag-source-pic-map-sort",
                    data:{"sort":newSort,"id":id},
                    success: function(msg){
                        if(msg.state==1){
                            swal({
                                title: "更新成功！",
                                text: "",
                                type: "success",
                                timer:2000
                            });
                            window.location.reload()
                        }else {
                            swal({
                                title: msg.message,
                                text: "",
                                type: "error",
                                timer:2000
                            });
                        }
                    },
                    error:function(){
                        swal({
                            title: "系统繁忙稍后再试",
                            text: "",
                            type: "error",
                            timer:2000
                        });
                    }
                });
            });
        });
        function deleteTagResourceMap(id) {
            swal({
                title: "确定删除？",
                text: "",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                closeOnConfirm: true,
                closeOnCancel: true
            },function (){
                $.ajax({
                    type: "post",
                    url: "/backstage/source-pic/delete-tag-resource-map",
                    data:{"id":id},
                    dataType: 'json',
                    success: function(res){
                        if(res.state==1){
                            swal({
                                title:'删除成功！',
                                text: "",
                                type: "success",
                                timer:2000
                            });
                            $('[data-tr-id='+id+']').remove();
                        }else{
                            swal({
                                title: res.message,
                                text: "",
                                type: "error",
                                timer:3000
                            });
                        }
                    },
                    error:function(){
                        swal({
                            title: "系统繁忙！",
                            text: "",
                            type: "error",
                            timer:2000
                        });
                    }
                });//ajax
            });
        }
        var state = 0;
        function addRang(th){
            if(state == 0){
                state = 1;
                var source_pic_id = $("#add_source_pic_id").val();
                console.log('source_pic_id:'+source_pic_id);
                console.log('tag_id:'+th);
                if(source_pic_id ==0){
                    swal('输入不正确～','','warning');
                    state = 0;
                    return ;
                }
                swal('处理中，请稍后','','warning');
                $.ajax({
                    type: "post",
                    url: "/backstage/source-pic/add-tag-source-pic-map",
                    data:{"tag_id":th,"resource_id":source_pic_id},
                    dataType: 'json',
                    success: function(res){
                        if(res.state ==1){
                            swal({title:'添加成功！', text: "", type: "success", timer:500});
                            location.reload();
                            return ;
                        }
                        swal(res.message,'','warning');
                    },
                    error:function(){
                        swal('系统繁忙','请稍后重试','warning');
                    }
                });
                state = 0;
            }
        }
        /***
         * 判断不超过三位整数
         * @param num
         * @returns {boolean}
         */
        function checkPositiveInteger(num) {
            var reg = /^\+?[1-9][0-9]{1,3}$ /;
            return reg.test(num);
        }
    </script>
@stop